package com.wshl.aijiuunion.controller.activity;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.widget.ImageView;

import com.blankj.utilcode.util.ImageUtils;
import com.blankj.utilcode.util.LogUtils;
import com.blankj.utilcode.util.ScreenUtils;
import com.blankj.utilcode.util.SizeUtils;
import com.bumptech.glide.Glide;
import com.bumptech.glide.request.target.SimpleTarget;
import com.bumptech.glide.request.transition.Transition;
import com.wshl.aijiuunion.BaseActivity;
import com.wshl.aijiuunion.R;
import com.wshl.aijiuunion.utils.ImageUnionUtil;
import com.wshl.aijiuunion.utils.QRCodeUtil;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created buy 风凊扬 on 2019/10/22 0022
 */
public class TestActivity extends BaseActivity {
    @BindView(R.id.img_scancode)
    ImageView imgScancode;

    @Override
    protected int getLayoutResource() {
        return R.layout.activity_test;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ButterKnife.bind(this);

        Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.logo);
//生成的二维码图片
        final Bitmap qr = QRCodeUtil.createQRImage("hello world", SizeUtils.dp2px(100), SizeUtils.dp2px(100), bmp);


        Glide.with(this)
                .asBitmap()
                .load("http://upload-images.jianshu.io/upload_images/2048265-44f59db66cecd375.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240")
                .into(new SimpleTarget<Bitmap>() {
                    @Override
                    public void onLoadFailed(@Nullable Drawable errorDrawable) {
                        super.onLoadFailed(errorDrawable);
                        LogUtils.i("图片下载失败");
                    }

                    @Override
                    public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {

                        LogUtils.i("图片下载成功");
                        //下载成功
                        if (qr != null) {
                            //合成图片
                            Bitmap bitmap = ImageUnionUtil.compoundBitmap(resource, qr);
                            if (bitmap != null) {
                                //将重新生成的图片显示到界面上
                                imgScancode.setImageBitmap(bitmap);
                            }
                        }
                    }

                });
        imgScancode.setImageBitmap(qr);
    }
}
